package com.lyl.serviceresume.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lyl.commonutils.R;
import com.lyl.serviceresume.entity.ResumeModel;
import com.lyl.serviceresume.service.ResumeModelService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前台简历模板 前端控制器
 * </p>
 *
 * @author 雷艳玲
 * @since 2022-07-24
 */
@RestController
@RequestMapping("/serviceresume/model")
public class ResumeModelController {

    @Autowired
    ResumeModelService modelService;


    @ApiOperation(value = "根据ID删除简历模板")
    @DeleteMapping("{id}")
    public R removeById(
            @ApiParam(name = "id", value = "模板ID", required = true)
            @PathVariable Long id){

        boolean result = modelService.removeById(id);
        if(result){
            return R.ok();
        }else{
            return R.error().message("删除失败");
        }
    }
    @ApiOperation(value = "简历模板分页")
    @PostMapping("{page}/{limit}")
    public R pageQuery(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Long page,

            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Long limit,

            @ApiParam(name = "courseQuery", value = "查询对象", required = false)
                    ResumeModel query){

        Page<ResumeModel> pageParam = new Page<>(page, limit);

        modelService.pageQuery(pageParam, query);
        List<ResumeModel> records = pageParam.getRecords();

        long total = pageParam.getTotal();

        return  R.ok().data("total", total).data("rows", records);
    }



    //添加课程基本信息的方法
    @PostMapping("addResumeModelInfo")
    public R addCourseInfo(@RequestBody ResumeModel resumeModel) {
        //返回添加之后课程id，为了后面添加大纲使用
      boolean isok=   modelService.save(resumeModel);
        if(isok) {
            return R.ok().message("添加成功");
        }else{
            return  R.error().message("添加失败");
        }
    }

    @PutMapping("updateResumeModelInfo")
    public R updateCourseInfo(@RequestBody ResumeModel resumeModel) {
        //返回添加之后课程id，为了后面添加大纲使用
        boolean isok = modelService.updateById(resumeModel);
        if(isok) {
            return R.ok().message(" 修改成功");
        }else{
            return  R.error().message("修改失败");
        }
    }

    @GetMapping("{id}")
    public R getById(@PathVariable("id") Integer id){

        return R.ok().data("resumeModel",modelService.getById(id));
    }


}

